﻿/**
给定一个包含 n 个整数的数组 nums，判断 nums 中是否存在三个元素 a，b，c ，使得 a + b + c = 0 ？找出所有满足条件且不重复的三元组。
注意：答案中不可以包含重复的三元组。
示例:
给定数组 nums = [-1, 0, 1, 2, -1, -4]，
满足要求的三元组集合为：
[
  [-1, 0, 1],
  [-1, -1, 2]
]

*/

/*

#include <vector>
#include <string>
#include "gmock/gmock.h"

using std::vector;
using namespace testing;

class ThreeNums_Solution {
public:
	vector<vector<int>> operator()(vector<int>& nums) {
		std::sort(nums.begin(), nums.end());
		
		vector<vector<int>> vctret;

		for (auto curIter = nums.begin(); curIter != nums.end(); ++curIter)
		{
			if (*curIter > 0)
			{
				break;
			}
			if (*curIter == *(curIter + 1))
			{
				continue;
			}

			auto left = curIter + 1;
			auto right = nums.end() - 1;

			while (left < right)
			{
				if (*left == *(left+1))
				{
					++left;
					continue;
				}
				if (*right == *(right - 1)) {
					--right;
					continue;
				}

				int sum = *curIter + *left + *right;
				if (sum == 0)
				{
					vctret.push_back({ *curIter, *left, *right });
					++left;
					--right;
				}
				else if (sum > 0)
				{
					--right;
				}
				else {
					++left;
				}
			}
			
			
			

		}
		
		return vctret;
	}
};
class ThreeNums_Test : public ::testing::Test {
public:
	ThreeNums_Solution sln;
};

TEST_F(ThreeNums_Test, first) {
	vector<int> vctInput{ -1, 0, 1, 2, -1, -4 };
	vector<vector<int>>  vctOutput{
		{-1, 0, 1},
		{-1, -1, 2}
	};
	
	ASSERT_THAT(sln(vctInput), Eq(vctOutput));
}

*/